#!/usr/bin/python
#
# Copyright (C) 2008 rambla.be
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

""" Contains the objects required for RATS total resource access. """

try:
  from xml.etree import cElementTree as ElementTree
except ImportError:
  try:
    import cElementTree as ElementTree
  except ImportError:
    from elementtree import ElementTree

import ratom 
import rawsc
from rawsc import RAWS_NAMESPACE
from rawsc.rams import *

class TotalParams(rawsc.RawsParams):
    """ Handler for the <raws:params> element (= sub-element of atom:content). """
    _children = {}
    _children['{%s}hits' % rawsc.RAWS_NAMESPACE] = ('hits', Hits)
    _children['{%s}volume' % RAWS_NAMESPACE] = ('volume', Volume)
    _children['{%s}updated' % rawsc.RAWS_NAMESPACE] = ('updated', Updated)
    _children['{%s}last_modified' % RAWS_NAMESPACE] = ('last_modified', LastModified)
    _children['{%s}events' % RAWS_NAMESPACE] = ('events', Events)
    _children['{%s}unique' % RAWS_NAMESPACE] = ('unique', Unique)

    def __init__(self, hits=None, volume=None, updated=None, last_modified=None, events=None, unique=None):
        rawsc.RawsParams.__init__(self, extension_elements=None, extension_attributes=None)
        self.hits = Hits(text = hits)
        self.volume = Volume(text = volume)
        self.updated = Updated(text = updated)
        self.last_modified = LastModified(text = last_modified)
        self.events = Events(text = events)
        self.unique = Unique(text = unique)

def TotalParamsFromString(xml_string):
    return ratom.CreateClassFromXMLString(TotalParams, xml_string)   


class TotalContent(rawsc.RawsContent):
    """ Handler for the atom:content element, in a RAWS context. """
    _children = ratom.AtomBase._children.copy()
    _children['{%s}params' % (RAWS_NAMESPACE)] = ('params', TotalParams)
    
    params = None
    
    def __init__(self, params=None):
        rawsc.RawsContent.__init__(self, extension_elements=None, extension_attributes=None)
        self.params = TotalParams()
        if params:
            self.params = params
    
def TotalContentFromString(xml_string):
    return ratom.CreateClassFromXMLString(TotalContent, xml_string)   
    

class TotalEntry(rawsc.RawsEntry):
    """ Handler for an entry that is returned by the RATS total resource."""
    _children = rawsc.RawsEntry._children.copy()
    _children['{%s}content' % ratom.ATOM_NAMESPACE] = ('content', TotalContent)
    _attributes = rawsc.RawsEntry._attributes.copy()
    _attributes['{%s}kind' % RAWS_NAMESPACE] = 'kind'
    _attributes['{%s}type' % RAWS_NAMESPACE] = 'type'

    def __init__(self, author=None, category=None, atom_id=None, link=None, published=None, title=None, updated=None, content = None, extension_elements=None, extension_attributes=None):
        rawsc.RawsEntry.__init__(self, author=author, category=category, atom_id=atom_id, link=link, published=published, title=title, updated=updated,
                                extension_elements=extension_elements, extension_attributes=extension_attributes)
        self.content = TotalContent()
        if content:
            self.content = content

def TotalEntryFromString(xml_string):
    return ratom.CreateClassFromXMLString(TotalEntry, xml_string)
    

class TotalFeed(rawsc.RawsFeed, rawsc.LinkFinder):
    """ Handler for a feed that is returned by the RATS total resource."""
    _children = rawsc.RawsFeed._children.copy()
    _children['{%s}entry' % ratom.ATOM_NAMESPACE] = ('entry', [TotalEntry])

def TotalFeedFromString(xml_string):
  return ratom.CreateClassFromXMLString(TotalFeed, xml_string)

